{% extends 'app01/base_backend.html' %}
  {% block person_manage %}
             <a class="navbar-brand" href="#">帖子收藏</a>
 {% endblock %}
{% block all_li %}
    <li role="presentation" class="active">
        <a href="#home" aria-controls="home" role="tab"data-toggle="tab">帖子收藏</a></li>
     <li role="presentation" class="active">
             <a href="{% url 'app01_backend' %}" style="color: #337ab7">返回个人管理</a></li>
{% endblock %}

{% block all_content %}

        {% block suibi %}
            <!--帖子收藏显示页面-->
            <hr>
            {% for article in col_article %}
                <div class="media">
                    <h4 class="media-heading"><a
                            href="/app01/site/{{ article.article.blog.userinfo.username }}/article/{{ article.article_id }}?url={{ request.get_full_path }}"
                            target="_blank">
                        {{ article.article.title }}</a></h4>
                    <div class="media-left">
                        <a href="#">
                            <img class="media-object" src="/media/{{ article.article.blog.userinfo.avatar }}/" alt="..."
                                 height="64">
                        </a>
                    </div>
                    <div class="media-body">
                        {{ article.article.desc }}
                        <br>
                        <br>
                        <div class="pull-right" style="color: #2ba4c7">
                            <a href="#" type="button" style="color: indianred" article_id="{{ article.article.pk }}" user_obj="{{ request.user }}" class="del_col_class">取消收藏</a>
                            &nbsp;&nbsp;&nbsp;作者：{{ article.article.blog.site_name }}&nbsp;&nbsp;&nbsp;
                            发布时间：{{ article.article.create_time }} </div>
                    </div>
                </div>
                <hr>

            {% empty %}
                <h3>您没有收藏过帖子。</h3>
            {% endfor %}

            {# 分页显示 #}
            <div class="pager">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        {{ article_page_html }}
                    </ul>
                </nav>
            </div>


        {% endblock %}

{% endblock %}

{% block js %}
    <script>
        if('{{ request.user.username }}'.slice(0,3)==='512'){
         $('#p_for_a').html('<a href="/app01/manage_student/" class="list-group-item">学生管理</a>')
        $('#role_for').html('角色：<br><a href="#">老师</a>')
    }


    if('{{ request.user.username }}'.slice(0,3)==='312'){

        $('#set_person_id').html('<p>班级：<input type="text" id="stu_class" class="form-control" value="{{ request.user.stu_class }}"></p>')
         $('#role_for').html('角色：<br><a href="#">学生</a>')
           $('#MyClass').html("<a href='/app01/myclass/'> 我的班级 </a>")
    }
    //取消收藏帖子
        $('.del_col_class').click(function () {
            //拿到自定义属性的属性值
            let user_obj = $(this).attr('user_obj')
            let article_id=$(this).attr('article_id')
            let op=confirm('是否取消收藏')
            if(op){
                 $.ajax({
                url:'',
                type:'post',
                data:{'article_id':article_id},
                success:function (attr) {
                    if(attr.code===100){
                        alert('移除收藏成功')
                        window.location.reload()
                    }
                    else {
                        alert(attr.msg)
                    }

                }
            })
            }


        })
    </script>
{% endblock %}